<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <title>Document</title>
</head>

<body>
  <h1>Index页面</h1>
  <button id="btn">给child发消息</button>

  <!-- <iframe src="https://www.ifeng.com/" frameborder="0"></iframe> -->

  <iframe id="ifr" src="./24-child.html" frameborder="1"></iframe>

  <script>
    let btn = document.getElementById("btn");
    btn.addEventListener("click", () => {
      window.ifr.contentWindow.postMessage("hello", "*")
    })

    window.addEventListener("message", e => {
      console.log(e.data);
      console.log(e.origin);
    })
  </script>
</body>

</html>